<template>
<div class="bg-white">
  <!--<ClassInfo @changeXkkh="changeXkkh" userIdentity="Student" barButton="!disable"></ClassInfo>-->
  <!--<mu-toast v-if="toast" message="保存成功!" />
  <div v-show="isOpen">
    <tag :nrbm="nrbm" :khdxbh='khdxbh' :khdxxm="khdxxm" userIdentity="student" lb="pj" ref="myTag" :disabled="disable"></tag>
  </div>-->
  <mu-bottom-nav @change="handleChange" class="bottom-btnbar" style="background-color: white; position: fixed;z-index: 300;">
    <mu-bottom-nav-item value="save" title="提交" icon="save"/>
    
     <mu-dialog :open="popCommissary" :title="popTitleInfo" @close="close">
		    <mu-flat-button slot="actions" @click="close('cancel')" primary label="取消"/>
		    <mu-flat-button slot="actions"  primary @click="close('sure')" label="确定"/>
		    <!--<mu-flat-button slot="actions" v-show="isSure" primary @click="close()" label="确定"/>-->
		  </mu-dialog>
		  
		  <mu-dialog :open="popCorrect" :title="popCorrectTitle" @close="close">
		    <mu-flat-button slot="actions" primary @click="close('correct')" label="确定"/>
		  </mu-dialog>
		  
  </mu-bottom-nav>
  <section style=" height: 3rem;"></section>
  	
    
		<!--<section >
    	 <mu-auto-complete style="margin-left: 4rem;" filter="noFilter" label="选择或输入课程" openOnFocus  labelFloat :dataSource="courseList" :maxHeight="200"  @change="ChoiceTeacher" v-model="courseName"  />
     </section>
    <section>
    	 <mu-auto-complete style="margin-left: 4rem;" filter="noFilter" label="选择或输入教师" labelFloat  :value="courTeaName" v-model="courTeaName" />
    </section>
     <section>
    	 <mu-auto-complete style="margin-left: 4rem;" filter="noFilter" label="选择或输入教师编号" labelFloat  :value="choiceTeacher" v-model="choiceTeacher" />
    </section>-->
    
    <section class="center-middle">
    	 <!--<mu-auto-complete style="margin-left: 4rem;" filter="noFilter" label="选择或输入课程" openOnFocus  labelFloat :dataSource="courseList" :maxHeight="200"  @change="ChoiceTeacher" v-model="courseName" />-->
    	 <mu-select-field v-model="courseIndex"  label="请选择课程">
    	 		 <mu-menu-item @click="linkageChoice(index)" v-for="(item,index) in courseList" :key="index" :value="index"   :title="item"/>
    	 </mu-select-field>
     </section>
    <section class="center-middle">
    	 <mu-auto-complete  filter="noFilter" label="教师姓名" labelFloat  :value="courTeaName" v-model="courTeaName"  underlineClass="defaultLine" disabled />
    </section>
     <section class="center-middle">
    	 <mu-auto-complete  filter="noFilter" label="教师编号" labelFloat  :value="choiceTeacher" v-model="choiceTeacher" underlineClass="defaultLine" disabled />
    </section>
    
    
  	<!--<mu-list>
  		<mu-list-item :title="item.evaluation_type_name" disableRipple  toggleNested v-for="(item,index) in typeInfo">
			    <mu-icon slot="left" color="orange500" value="inbox"/>
			    <section v-for="(itemC,indexC) in contentInfo">
			    			<mu-list-item slot="nested"  disableRipple v-if="item2.evaluation_type_id==item.evaluation_type_id"  v-for="(item2,index2) in itemC">
						    	<mu-avatar slot="left" color="white"  backgroundColor="blue500">{{item2.evaluation_level_id}}</mu-avatar>
						    	
						        <div class="zss_bq">{{item2.evaluation_content_name}}</div>
						    </mu-list-item>	
			    </section>
			     
			</mu-list-item>
  	</mu-list>-->
  	  		<mu-list v-for="(item,index) in contentInfo">
			    <mu-list-item :title="indexT" disableRipple  toggleNested v-for="(itemT,indexT) in item">
				    <mu-icon slot="left" color="orange500" value="inbox"/>
				    <mu-list-item slot="nested"  disableRipple v-for="(itemL,indexL) in itemT">
					    <mu-list-item  v-for="(itemLC,indexLC) in itemL" disableRipple v-show="!(indexLC=='levelInfo')">
					    	<mu-avatar slot="left" color="white" backgroundColor="blue500" >{{indexLC}}</mu-avatar>
					    	<div style="padding-right:42px" >
					        <!--<div @click="tagClick(bq,lb,xx)" class="zss_bq" v-bind:class="{disable:disabled,zss_djbs:bq.xz}" v-for="(bq ,tIndex) in xx.bqList">{{bq.BQMC}}</div>-->
					        <!--<div v-for="(itemLD ,indexLD) in itemLC"  @click="passClick(itemT,indexL,indexLC,itemLD,itemL,index)" :class="(itemLD.contInfo&&itemL.levelInfo)?'bgChoice':'zss_bq'">
					        	{{itemLD.name}}
					        </div>-->
					        
					        <div v-for="(itemLD ,indexLD) in itemLC"  @click="passClick(itemT,indexL,indexLC,itemLD,itemL,index,indexT)" :class="btnStyle(itemLD.contInfo,itemL.levelInfo)" >
					        	{{itemLD.name}}
					        </div>
					        
					      </div>
					    </mu-list-item>	 
				    </mu-list-item>
					</mu-list-item>
	    </mu-list>
	    
	    <div v-show="isLoading" class="loading">
				<mu-circular-progress :size="22" color="green500"/>
				<div>加载中..</div>
			</div>

	    
	    <section style="height: 3rem;"></section>
  </div>
</template>
<script>
	import axios from 'axios'
//import Tag from '@/components/tag'
//import ClassInfo from '@/components/class_info'
export default {
  name:'Student',
  data () {
    return {
      toast:false,
      nrbm:'',
      khdxbh:'',
      khdxxm:'',
      isLoading:true,
      disable:false,
      isOpen:false,
      allParameters:{},
      ktxq:{},
      popTitleInfo:'',
      isSubmitThis:false,
      popCommissary:false,
      typeInfo:{},
      contentInfo:{},
      className:'',
      arr1:[],
      teachEva:[],
      isLine:false,
      courseList:[],
      courseData:[],
      classroomPosition:[],
      teacherName:[],
      teacherId:[],
      getIndex:0,
      courseName:'',
      courTeaName:'',
      classPosition:'',
      publicInfo:{
	    	academic:'',
	    	semester:'',
	    	teachWeek:''
		  },
		  currentTime:'',
		  currentmonth:'',
		  currentFullDate:'',
		  isTest:false,
			upload:{},
			finalArr:[],
			finalStr:'',
			choiceTeacher:'',
			isSure:false,
			popCorrect:false,
			popCorrectTitle:'',
			defaultState:true,
			courseIndex:-1,
			isContentAll:[],
			finalRight:[],
			publicSubmit:{},
			submitFinal:[]
    }
  },
  components:{
//		  Tag,
//		ClassInfo
  },mounted(){
//  let that=this
//  let time = setInterval(()=>{
//    let kqsj=that.ktxq["SJ"].replace(/-/g,'/')
//    //点名时间计算开始
//    let classStart = new Date(kqsj+" "+that.allParameters[that.ktxq["DJJ"]+"_class_start"]).getTime()
//    let classEnd = new Date(kqsj+" "+that.allParameters[(parseInt(that.ktxq["DJJ"])+parseInt(that.ktxq["SKCD"])-1)+"_class_end"]).getTime()
//    let beforeTime = parseInt(that.allParameters["roll_call_before_start"])*60000
//    let afterTime = parseInt(that.allParameters["roll_call_after_end"])*60000
//    classStart -=beforeTime
//    classEnd +=afterTime
//    //点名时间计算完成
//    //课堂日志截止时间
//    let commissary_log_end = new Date(kqsj+" "+that.allParameters["commissary_log_end"]).getTime()
//    //学生评教截止时间
//    let student_evaluate_end = new Date(kqsj+" "+that.allParameters["student_evaluate_end"]).getTime()
//    //教师评学截至时间
//    let teacher_evaluate_end = new Date(kqsj+" "+that.allParameters["teacher_evaluate_end"]).getTime()
//    let teacher_evaluate_open = that.allParameters["teacher_evaluate_open"]
//    let student_evaluate_open = that.allParameters["student_evaluate_open"]
//    let nT = new Date()
//    let timeNow = nT.getTime()
//    if(timeNow>classStart && timeNow<student_evaluate_end){
//      that.disable=false
//    }else{
//      that.disable=true
//    }
//    //console.info(endTime);
//  },1000)
			this.variousTime()
			this.getPublicInfo()
//			this.loadCoureInfo()
			this.getContentInfo()
			this.className=localStorage.classId
			this.getElectiveCourse()
  },
  watch:{
  	courseName(val1,Val2){
//			this.studentEvaluation()
			
  	},
  },
  computed:{
		urlDayCourse:function(){
			return 'iyx/course/'+this.currentFullDate+'/'+localStorage.classId+'/ClassDayCourse?token='+localStorage.token
		}
	},
  methods: {
  	//评教获取信息
  	linkageChoice(val){
  			this.courseName=this.courseList[val]
			  this.courTeaName=this.courseData[val].teacherName
			  this.choiceTeacher=this.courseData[val].teacherId
			  this.publicSubmit.id=this.courseData[val].id
			  this.publicSubmit.studentId=this.courseData[val].studentId
			  this.publicSubmit.studentName=this.courseData[val].studentName
			  this.publicSubmit.teacherId=this.courseData[val].teacherId
			  this.publicSubmit.teacherName=this.courseData[val].teacherName
			  this.publicSubmit.courseName=this.courseData[val].courseName
			  this.publicSubmit.courseId=this.courseData[val].courseId
			  this.publicSubmit.courseTime=this.courseData[val].courseTime
			  this.publicSubmit.courseWhichIndex=this.courseData[val].courseWhichIndex
			  this.publicSubmit.courseClassroom=this.courseData[val].courseClassroom
			  this.publicSubmit.evaluationTime=this.courseData[val].courseTime
  	},
  	studentEvaluation(){
  			let that=this
//			that.axios.get('/iyx/evaluation/'+that.choiceTeacher+'/'+localStorage.userNumber+'/'+that.courseName+'/EvaluationInfo').then(function(response){
//					console.info(response.data)
//					var evalData2=that.contentInfo
//					for(var i in evalData2){
//							for(var j in evalData2[i]){
//									for(var a in evalData2[i][j]){
//										evalData2[i][j][a]['levelInfo']=false
//										for(var b in evalData2[i][j][a]){
//												for(var c=0;c<evalData2[i][j][a][b].length;c++){
//													evalData2[i][j][a][b][c]['contInfo']=false
//												}
//										}
//									}
//							}
//						}
//			}).catch(function (error) {
//	        	console.log(error);
//	      	});
  	},
  	btnStyle(contState,levelState){
  			if(this.defaultState){
  					if(contState && levelState){
  						return 'bgChoice'
  					}else{
  						return 'zss_bq'
  					}
  			}else{
  				  return 'disableClass'
  			}
  	},
  	dealFinal(data){
  		this.finalStr=''
  		for(var i in data){
  				for(var j in data[i]){
  						this.finalStr=this.finalStr+(data[i][j].slice(2))+','
  				}
  		}
//		
  	},
  	dealArr(data){
  		var lastArr=[]
  		for(var i in data){
  				for(var j in data[i]){
  					  lastArr.push(data[i][j])
  				}
  		}
  		for(var i in lastArr){
  				lastArr[i]=lastArr[i].split("-")
  		}
//		var turnArrEle=lastArr[0].split("-")
			this.finalRight=lastArr
			
  		var checkTemp=[]
//		var publicSubmitTemp=this.publicSubmit
  		
  		for(var i=0; i<this.finalRight.length;i++){
  				var publicSubmitTemp={}
  				publicSubmitTemp.id=this.publicSubmit.id
					publicSubmitTemp.studentId=this.publicSubmit.studentId
					publicSubmitTemp.studentName=this.publicSubmit.studentName
			  	publicSubmitTemp.teacherId=this.publicSubmit.teacherId
			  	publicSubmitTemp.teacherName=this.publicSubmit.teacherName
			  	publicSubmitTemp.courseName=this.publicSubmit.courseName
			  	publicSubmitTemp.courseId=this.publicSubmit.courseId
			  	publicSubmitTemp.courseTime=this.publicSubmit.courseTime
			  	publicSubmitTemp.courseWhichIndex=this.publicSubmit.courseWhichIndex
			  	publicSubmitTemp.courseClassroom=this.publicSubmit.courseClassroom
			    publicSubmitTemp.evaluationTime=this.publicSubmit.courseTime
	  			publicSubmitTemp.evaluationType=this.finalRight[i][0]
					publicSubmitTemp.evaluationLevel=this.finalRight[i][1]
					publicSubmitTemp.evaluationContent=this.finalRight[i][2]
					checkTemp.push(publicSubmitTemp)
  		}
//		console.info(checkTemp)
  		this.submitFinal=checkTemp
  	},
  	initialData(){
  		for(var i in this.contentInfo){
  			this.upload[i]=[]
//			for(var j in this.upload[i]){
//				
//			}
  		}
  	},
  	passClick(data1,data2,data3,val,typeVal,indexAll,evaluationType){
  		//此方法为评教选中生成一个选中内容的json
		  		for(var i in data1){
						if(data2!=i){
							data1[i].levelInfo=false
			  					for(var j in data1[i]){
				  						if(j!='levelInfo'){
				  							for(var c in data1[i][j]){
				  								data1[i][j][c].contInfo=false
				  							}
				  						}
			  					}
						}else{
								data1[data2].levelInfo=true
						}
		  		}
		  		
						//此过滤废了好几天工作量
				  if(this.upload[indexAll].indexOf(evaluationType+'-'+data3+'-'+val.name)==-1){
				  		
							this.upload[indexAll].push(evaluationType+'-'+data3+'-'+val.name)
							val.contInfo=true
							var frontStr=evaluationType+'-'+data3
							this.upload[indexAll]=this.upload[indexAll].filter(function(elm){
									if(elm.slice(0,6)!=frontStr.slice(0,6)){
										return elm.slice(0,6)==frontStr.slice(0,6)
									}else{
										return elm
									}
			  			})
					}else{
						  this.upload[indexAll]=this.upload[indexAll].filter(function(cont){
			  				return cont!=(evaluationType+'-'+data3+'-'+val.name)
			  			})
			  			val.contInfo=false
					}
//					console.info(evaluationType)
//					console.info(val)
//					console.info(data3)
//					console.info(this.upload)
					this.dealArr(this.upload)
					this.getIsAllChoice()
					
  	},
  	getIsAllChoice(){
  		
  	},
  	getPublicInfo(data){
  			let that=this
  			that.axios.get('/iyx/courseDate/getDayInfo/'+that.currentFullDate).then(function(response){
  				that.publicInfo.academic=response.data.courseAcademicYear
				  that.publicInfo.semester=response.data.courseAcademicTerm
				  that.publicInfo.teachWeek=response.data.courseWhichWeek
//					that.getAllCourse()
					that.loadCoureInfo()
  			})
  	},
  	loadCoureInfo(){
			//获取该班当天课程信息
			let that = this
	      	that.axios.get(that.urlDayCourse).then(function (response) {
	      		that.todayCourse=response.data
//	        	that.getAllCourse()
	      	}).catch(function (error) {
	        	console.log(error);
	      	});
		},
		//获取选修课课程信息
	getElectiveCourse(){
  	  let that= this
      that.axios.get('iyx/electiveCourseEvaluation/getElectiveCourseList').then(function (response) {
        
        if(response.data.msg=='success'){
        	that.courseData = response.data.list
        }
//      console.info(that.courseData)
        for(var i in that.courseData){
        	that.courseList.push(that.courseData[i].courseName)
        }
//      for(var i in  that.courseData){
//      	that.teacherId.push(that.courseData[i].courseTeacherId)
//      	that.courseList.push(that.courseData[i].courseName)
//      	that.teacherName.push(that.courseData[i].courseTeacherName)
//      }
//      console.info(that.courseList)
//      console.info(that.teacherName)
      }).catch(function (error) {
      })
  	},
  	variousTime(){
    	var thisDate=new Date()
			var currentYear=thisDate.getFullYear()
	  	var mon=this.correcTime(thisDate.getMonth()+1)       
	  	var toDate=this.correcTime(thisDate.getDate())
	  	var currentHour=this.correcTime(thisDate.getHours()) 
	  	var currentMinutes=this.correcTime(thisDate.getMinutes())
	  	var currentSeconds=this.correcTime(thisDate.getSeconds())
			this.currentmonth=mon+'-'+toDate
	  	this.currentTime=currentHour+':'+currentMinutes+':'+currentSeconds
	  	this.currentFullDate=currentYear+'-'+this.currentmonth
    },
    correcTime(data){
    	if(data<10){
    		data='0'+data
    	}
    	return data
    },
  	submitData(){
  		let that = this;
  		this.finalStr=this.finalStr.slice(0,this.finalStr.length-1)
			axios.post('/iyx/evaluation/insertEvaluation?token='+localStorage.token, {
						 "courseId":that.courseName,
             "teacherId": that.choiceTeacher,
						  "studentId": localStorage.userNumber,
						  "evaluationTime":that.currentFullDate+''+that.currentTime,
						  "evaluationContent":that.finalStr
            }).then(function (response) {
             if(response.data.slice(1)=='操作完成'){
             		that.$parent.showToast('提交成功')
             		setTimeout(function(){
             			 that.getContentInfo()
             		},1200)
             }else{
             		that.$parent.showToast('提交失败')
             }
             
          })
          .catch(function (error) {
            that.$parent.showToast('提交失败')
          });
  	},
  	submitElective(){
  		let that = this;
//		this.finalStr=this.finalStr.slice(0,this.finalStr.length-1)
			axios.post('/iyx/electiveCourseEvaluation/insertEvaluation',that.submitFinal).then(function (response) {
	            	console.info(response.data)
		           if(response.data.msg=='success'){
		           		that.$parent.showToast('提交成功')
		           		setTimeout(function(){
		           			 that.getContentInfo()
		           		},1200)
		           }else{
		           		that.$parent.showToast('提交失败')
		           }
             
          })
          .catch(function (error) {
            that.$parent.showToast('提交失败')
          });
  	},
  	getContentInfo(){
  		let that=this
  		that.axios.get('/iyx/evaluation/ContentInfo2?token='+localStorage.token).then(function(response){

  			var tempShow=response.data
  			var evalData=response.data
				for(var i in evalData){
						for(var j in evalData[i]){
								for(var a in evalData[i][j]){
									evalData[i][j][a]['levelInfo']=false
									for(var b in evalData[i][j][a]){
											for(var c=0;c<evalData[i][j][a][b].length;c++){
												evalData[i][j][a][b][c]['contInfo']=false
											}
									}
								}
						}
					
				}
				that.isLoading=false
				that.contentInfo=evalData
//				console.info(that.contentInfo)
				that.initialData()
  		}).catch(function(error){
  					console.log(error)
  		})
  	},
  	//是否选择老师和课程
  	handleChange(val){
    	if(val=='save'){
				this.dealFinal(this.upload)
				
				 this.variousTime()
				 this.submitThis()
				
    	}
    },
    ChoiceTeacher(val){
    	var n=this.teacherName.indexOf(val)
    	this.choiceTeacher=this.teacherId[n]
    },
		submitThis(){
					var arrType=['教学态度','教学效果','教学内容','教学环节']
					var totalChoice=[]
				  for(var i in this.contentInfo){
				  		for(var j in this.contentInfo[i][arrType[i]]){
				  				if(this.contentInfo[i][arrType[i]][j].levelInfo){
				  						totalChoice.push(this.contentInfo[i][arrType[i]][j].levelInfo)
//				  						console.info(totalChoice)
				  				}
				  		}
				  }
					if(this.courseName.length!=0){
  						if(this.courTeaName.length!=0){
  								if(this.choiceTeacher.length!=0){
  										if(totalChoice.length==4){
	  											this.open()
										    	this.isSubmitThis=true
										    	this.popTitleInfo='确定要提交吗？'
  										}else{
  												this.popCorrectTitle="请在每一项选择一条评教内容！"
  												this.popCorrect=true
  										}
  								}else{
  										this.popCorrectTitle="教师编号不能为空！"
  										this.popCorrect=true
  								}
  						}else{
  								this.popCorrectTitle="教师名字不能为空！"
  								this.popCorrect=true
  						}
  				}else{
  						this.popCorrectTitle="课程名称不能为空！"
  						this.popCorrect=true
  				}
//  	this.open()
//  	this.isSubmitThis=true
//  	this.popTitleInfo='确定要提交吗？'
    },
  	open () {
      this.popCommissary = true
    },
    close (val) {
    	if(val=='sure'){
	    		if(this.isSubmitThis){
	    			this.submitElective()
//	    			this.save()
	    		}else{
	      	}
      }else if(val=='correct'){
      		this.popCorrect=false
      }
      this.popCommissary = false
    },
	ChoiceTeacher(val){
			this.courseName=val
			var n=this.courseList.indexOf(val)
			this.courTeaName=this.teacherName[n]
			this.choiceTeacher=this.teacherId[n]
    }
		
//  changeXkkh(ktxq,allParameters){
//    let that=this
//    that.ktxq=ktxq
//    that.allParameters=allParameters
//    that.nrbm=ktxq.NRBM
//    that.khdxbh=ktxq.JSGH
//    that.khdxxm=ktxq.RKJS
//    if(allParameters.student_evaluate_open==0){
//      that.isOpen = false
//    }else{
//      that.isOpen=true
//    }
//  },
//  save(){
//    this.$refs.myTag.submit()
//    this.toast = true
//    if (this.toastTimer) clearTimeout(this.toastTimer)
//    this.toastTimer = setTimeout(() => { this.toast = false }, 1000)
//  }
  }
 
}
</script>
<style scoped>
	*{
		padding: 0;
		margin: 0;
	}
	.center-middle{
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.disPlay{
		display: none !important;
	}
	
	.loading{
		text-align: center;
		margin-top: 3.5rem;
	}
	.zss_bq{
			border:1px solid #ffa809;
			color: black;
			display: inline-block;
			padding: 0.25rem; 
			border-radius:3px;
			margin:0.2rem;
			font-size: 0.9rem;
	}
	.bgChoice{
			background-color: #ffa809;
			display: inline-block;
			padding: 0.25rem;
			border-radius:3px;
			margin:0.2rem;
			color:#fff;
			font-size: 0.9rem;
			border:1px solid #ffa809;
	}
	.bgDefault{background-color:seashell}
	.active{background-color: #ffa809;color:#fff!important}
	.disableClass{
		border-color: #bdbbb7;
		background-color: #dadada;
		display: inline-block;
		padding: 0.25rem;
		border-radius:3px;
		margin:0.2rem;
		/*color: #bdbbb7;*/
		font-size: 0.9rem;
	}
</style>